package com.nanhu.sms;

import com.nanhu.sms.widget.DashlineEditTextOne;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class SmsViewActivity extends Activity{
	
	private TextView sender;
	
	private TextView date;
	
	private DashlineEditTextOne content;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sms_view_layout);
		
		sender = (TextView)findViewById(R.id.sender);
		date = (TextView)findViewById(R.id.date);
		content = (DashlineEditTextOne)findViewById(R.id.content);
		init();
	}
	
	private void init(){
		Intent intent = getIntent();
		long id = intent.getLongExtra("id", 0);
		if(id > 0){
			ContentResolver cr = getContentResolver();
			Uri uri = Uri.parse(SmsListFragment.SMS_URI_ALL);
			Cursor c = cr.query(uri, SmsListFragment.projection, "_id=?", new String[]{id+""}, null);
			if(c.moveToFirst()){
				String strSender = c.getString(c.getColumnIndex("address"));
				String strContent = c.getString(c.getColumnIndex("body"));
				sender.setText(strSender);
				content.setText(strContent);
			}
			if(!c.isClosed()){
				c.close();
			}
		}
	}
}
